<%--
  Created by IntelliJ IDEA.
  User: HW
  Date: 2018/4/19
  Time: 1:04
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<script type="text/javascript" src="../../js/jquery-1.11.0.js"></script>
<script type="text/javascript" src="../../js/jquery-migrate-1.2.1.js"></script>
<script src="../../js/jquery.js"></script>
<head>
    <title>乡镇图书管理系统</title>
</head>
<body style="background:cornflowerblue;height: 100%">
<div align="center">
    <table style="width: auto" border="1">
        <thead>
        <tr>
            <td align="center" colspan="4">
                <h1>乡镇图书管理系统</h1>
            </td>
        </tr>
        </thead>
        <tr>
            <td>
                <form>
                    <input type="hidden" name="bookId" id="bookId">
                    <p>图书名称<input type="text" id="bookName" name="bookName" required="true"/></p>
                    <p>图书类型<input list="typelist" id="bookType" contenteditable="false" name="bookType"/></p>
                    <p>图书作者<input type="text" id="author" name="author"/></p>
                    <p style="text-align: center;width: 100%"><input type="submit" value="提交" onclick="ifAddBook()"></p>
                </form>
            </td>
        </tr>
        <datalist id="typelist">
            <option>1</option>
            <option>2</option>
            <option>3</option>
            <option>4</option>
            <option>5</option>
        </datalist>
    </table>
</div>
</body>
<script type="text/javascript">
    function ifAddBook() {
        if($("#bookName").val()==""){
            alert("请填写书名");
        }else {
        if($("#bookType").val()==""){
            alert("请选择类型");
        }else {
            if($("#author").val()==""){
                alert("请填写作者");
            }else {
                var addType = confirm("确定添加吗？");
                if (addType) {
                    $.ajax({
                            type: "post",
                            url: "/book/addBook",
                            dataType: "json",
                            data: {
                                bookName:$("#bookName").val(),
                                bookType: $("#bookType").val(),
                                author:$("#author").val(),
                            },
                            success: function (data) {
                                if (data == 1) {
                                    alert("添加成功");
                                } else {
                                    alert("添加失败");
                                }
                            }
                        }
                    );
                }}
        }
        }

    }
</script>
</html>
